﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Model;
using BusinnessLogic;

namespace scrumbench
{
    public partial class ImpedimentsLibraryForm : Form
    {
        public List<Impediments> detailmeegeven = new List<Impediments>();
        public ImpedimentsLibraryForm()
        {
            InitializeComponent();

            ImpedimentsManage fill = new ImpedimentsManage();
            detailmeegeven = fill.FillImpedimentsViewtje();
        }


        private void FillListView(object sender, EventArgs e)
        {
            List<Impediments> listje = new List<Impediments>();
            ImpedimentsManage fill = new ImpedimentsManage();
            listje = fill.FillImpedimentsViewtje();
            foreach (Impediments imp in listje)
            {
                ListViewItem item = new ListViewItem();
                item.Text = imp.impedimentID.ToString();
                listView1.Items.Add(item);
                ListViewItem.ListViewSubItem subitem = new ListViewItem.ListViewSubItem();
                subitem.Text = imp.titel;
                item.SubItems.Add(subitem);
                ListViewItem.ListViewSubItem subitemuser = new ListViewItem.ListViewSubItem();
                subitemuser.Text = imp.Username;
                item.SubItems.Add(subitemuser);
                ListViewItem.ListViewSubItem subitemtaskid = new ListViewItem.ListViewSubItem();
                subitemtaskid.Text = imp.Task;
                item.SubItems.Add(subitemtaskid);
            }
        }

        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.listView1.SelectedItems != null)
            {
                foreach (Impediments detail in detailmeegeven)
                {
                    if (detail.impedimentID == int.Parse(listView1.SelectedItems[0].SubItems[0].Text))
                    {
                        int id = detail.impedimentID;

                        ImpedimentDetailsForm nImpedimentsDetail = new ImpedimentDetailsForm(id);
                        nImpedimentsDetail.Show();
                    }
                    else if (listView1.SelectedItems == null)
                    {
                        MessageBox.Show("You haven't selected an impediment");
                    }

                }

            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }

}
